<?php
namespace app\api\controller\v1;
use app\api\controller\Common;

class MemberCard extends Common{
	var $modelDb;
	public function _initialize(){
		parent::_initialize();
		$this->modelDb = model("MemberCard");
	}
	public function add(){
		$this->postData['userid'] = $this->uinfo['id'];
        $id = $this->modelDb->save_data($this->postData);
        if($id === false){
            return $this->app_error($this->modelDb->getError());
        }
        else{
            $info = $this->modelDb->get_data(['item_id'=>$id]);
        }
    	return $this->app_success($info);
    }
	public function update(){
		$this->postData['userid'] = $this->uinfo['id'];
        $this->postData['card'] = $this->modelDb->where('userid', $this->uinfo['id'])->value('card');
        $id = $this->modelDb->update_data($this->postData);
        if($id === false){
        	return $this->app_error($this->modelDb->getError());
        }
        else{
            $info = $this->modelDb->get_data(['item_id'=>$id]);
        }
    	return $this->app_success($info);
    }
}